<?php
namespace Admin\Controller;

class AttendController extends BaseController {


    public function _before_index() {
        // 查找当前用户的教学计划
        $teachplanList = D ("Teachplan")->getAllTeachplanByTid($this->admin['id']);
        $this->assign('teachplanList',$teachplanList);
    }


    public function index() {

        $teachplan_id = I ('request.tid');
        $teachplan = D ("Teachplan")->_get($teachplan_id);
        //if (empty($teachplan))
        //    $this->error("教学计划不存在");

        $attendList = D ("Attend")->getAttendByTid($teachplan_id);
        foreach ($attendList as $k=>$v) {
            $attendList[$k]['teachplan_name'] = $teachplan['name'];
            $attendList[$k]['teacher_name'] = $this->admin['name'];
            $attendList[$k]['status'] = $this->getStatus($v['status']);
        }

        $this->assign('attendList',$attendList);
        $this->assign('teachplan', $teachplan);
        $this->display();
    }


    /**
     * 导出考勤记录
     */
    public function export() {

        $teachplan_id = I ('request.tid');
        $teachplan = D ('Teachplan')->_get($teachplan_id);
        if (empty($teachplan))
            $this->error("教学计划不存在");

        $xlsData = D ("Attend")->getAttendByTid($teachplan_id);
        foreach ($xlsData as $k=>$v) {
            $xlsData[$k]['week'] = "第 {$v['week']} 周";
            $xlsData[$k]['xq'] = "星期 {$v['xq']}";
            $xlsData[$k]['jc'] = "第 {$v['start']} ~ {$v['end']} 节";
            $xlsData[$k]['status'] = $this->getStatus($v['status']);
        }

        $xlsName = $teachplan['name'] . " 出勤情况统计表";
        $xlsCell = array (

            array('student_id','学号'),
            array('student_name','学生姓名'),
            array('week', '周次'),
            array('xq','星期'),
            array('jc','节次'),
            array('status','出勤状态'),

        );

        exportExcel($xlsName,$xlsCell,$xlsData);
    }


    /**
     * 将状态参数改为状态字符串
     *
     * @param $status
     * @return string
     */
    private function getStatus($status) {

        return "状态";

        switch ($status) {

        }
    }


}